home *** CD-ROM | disk | FTP | other *** search
/ 17 Bit Software 3: The Continuation / 17-Bit_The_Continuation_Disc.iso / amigan / amigan 5 / wbrun / _main.c next >
Encoding:
C/C++ Source or Header  |  1994-01-27  |  3.2 KB  |  146 lines

  1. /*    _main.c        Copyright (C) 1985  Lattice, Inc.    */
  2.  
  3. #include "stdio.h"
  4. #include "fcntl.h"
  5. #include "ios1.h"
  6.  
  7. #include "workbench/startup.h"
  8. #include "libraries/dos.h"
  9. #include "libraries/dosextens.h"
  10.  
  11. #define MAXARG 32              /* maximum command line arguments */
  12. #define QUOTE  '"'
  13.  
  14. #define isspace(c)    ((c == ' ')||(c == '\t') || (c == '\n'))
  15.  
  16. #ifndef TINY
  17. extern int _stack,_fmode,_iomode;
  18. extern int (*_ONBREAK)();
  19. extern int CXBRK();
  20. #endif
  21. extern int LoadAddress;
  22.  
  23. extern struct UFB _ufbs[];
  24. int argc;            /* arg count */
  25. char *targv, *argv[MAXARG];    /* arg pointers */
  26.  
  27. #define MAXWINDOW 40
  28. extern struct WBStartup *WBenchMsg;
  29. static char window[MAXWINDOW] = "con:10/10/320/80/";
  30. static struct Process *process, *FindTask();
  31. static struct FileHandle *handle;
  32.  
  33. /**
  34. *
  35. * name         _main - process command line, open files, and call "main"
  36. *
  37. * synopsis     _main(line);
  38. *              char *line;     ptr to command line that caused execution
  39. *
  40. * description    This function performs the standard pre-processing for
  41. *        the main module of a C program.  It accepts a command
  42. *        line of the form
  43. *
  44. *            pgmname arg1 arg2 ...
  45. *
  46. *        and builds a list of pointers to each argument.  The first
  47. *        pointer is to the program name.  For some environments, the
  48. *        standard I/O files are also opened, using file names that
  49. *        were set up by the OS interface module XCMAIN.
  50. *
  51. **/
  52. void _main(line)
  53. register char *line;
  54. {
  55. register char **pargv;
  56. register int x;
  57.  
  58. /*
  59. *
  60. * Build argument pointer list
  61. *
  62. */
  63. while (argc < MAXARG)
  64.     {
  65.     while (isspace(*line))    line++;
  66.     if (*line == '\0')    break;
  67.     pargv = &argv[argc++];
  68.     if (*line == QUOTE)
  69.         {
  70.         *pargv = ++line;  /* ptr inside quoted string */
  71.         while ((*line != '\0') && (*line != QUOTE)) line++;
  72.         if (*line == '\0')  XCEXIT(1);
  73.         else            *line++ = '\0';  /* terminate arg */
  74.         }
  75.     else        /* non-quoted arg */
  76.         {     
  77.         *pargv = line;
  78.         while ((*line != '\0') && (!isspace(*line))) line++;
  79.         if (*line == '\0')  break;
  80.         else             *line++ = '\0';  /* terminate arg */
  81.         }
  82.     }  /* while */
  83. targv = (argc == 0) ? (char *)WBenchMsg : (char *)&argv[0];
  84.  
  85.  
  86. /*
  87. *
  88. * Open standard files
  89. *
  90. */
  91. #ifndef TINY
  92.  
  93. if (argc == 0)        /* running under workbench    */
  94.     {
  95.     strncat(window, WBenchMsg->sm_ArgList->wa_Name,MAXWINDOW);
  96.     _ufbs[0].ufbfh = Open(window,MODE_NEWFILE);
  97.     _ufbs[1].ufbfh = _ufbs[0].ufbfh;
  98.     _ufbs[1].ufbflg = UFB_NC;
  99.     _ufbs[2].ufbfh = _ufbs[0].ufbfh;
  100.     _ufbs[2].ufbflg = UFB_NC;
  101.     handle = (struct FileHandle *)(_ufbs[0].ufbfh << 2);
  102.     process = FindTask(0);
  103.     process->pr_ConsoleTask = handle->fh_Type;
  104.     x = 0;
  105.     }
  106. else            /* running under CLI        */
  107.     {
  108.     _ufbs[0].ufbfh = Input();
  109.     _ufbs[1].ufbfh = Output();
  110.     _ufbs[2].ufbfh = Open("*", MODE_OLDFILE);
  111.     x = UFB_NC;            /* do not close CLI defaults    */
  112.     }
  113.  
  114. _ufbs[0].ufbflg |= UFB_RA | O_RAW | x;
  115. _ufbs[1].ufbflg |= UFB_WA | O_RAW | x;
  116. _ufbs[2].ufbflg |= UFB_RA | UFB_WA | O_RAW;
  117.  
  118. x = (_fmode) ? 0 : _IOXLAT;
  119. stdin->_file = _ufbs[0].ufbfh;
  120. stdin->_flag = _IOREAD | x;
  121. stdout->_file = _ufbs[1].ufbfh;
  122. stdout->_flag = _IOWRT | x;
  123. stderr->_file = _ufbs[2].ufbfh;
  124. stderr->_flag = _IORW | x;
  125.  
  126. /*    establish control-c handler */
  127.  
  128. _ONBREAK = CXBRK;
  129.  
  130. #endif
  131.  
  132. /*
  133. *
  134. * Call user's main program
  135. *
  136. */
  137.  
  138. main(argc,targv);              /* call main function */
  139. #ifndef TINY
  140. exit(0);
  141. #else
  142. XCEXIT(0);
  143. #endif
  144. }
  145.  
  146.